package opertion;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class DeletOpertion implements IOperation {
        @Override
        public void work(BookList bookList) {
                Scanner sc = new Scanner(System.in);
                System.out.println("请输入要删除的书名");
                String name = sc.nextLine();
                int flag = -1;
                for (int i = 0; i < bookList.getUsedSize(); i++) {
                        if (bookList.getBooks()[i].getName().equals(name)) {
                                flag = i;
                        }
                }
                if (flag != -1) {
                        for (int i = flag; i < bookList.getUsedSize() - 1; i++) {
                                bookList.getBooks()[i] = bookList.getBooks()[i + 1];
                        }
                        bookList.setUsedSize(bookList.getUsedSize() - 1);
                        System.out.println("删除成功");
                } else {
                        System.out.println("没有该书");
                }
        }
}
